package com.shop.service.impl;

import com.shop.bean.Admin;
import com.shop.bean.User;
import com.shop.dao.AdminDao;
import com.shop.dao.UserDao;
import com.shop.service.IShoppingRegisterService;
import com.shop.service.ISystemRegisterService;
import com.shop.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SystemRegisterService implements ISystemRegisterService {

    @Autowired
    AdminDao adminDao;


    @Override
    public Admin doregister(Admin admin) {
        Admin admin_data=adminDao.getAdminByUsername(admin.getUsername());
        if(admin_data != null){
            throw new RuntimeException("账号已存在！");
        }
        String hexpass= SYS.digest(admin.getPassword());
        admin.setPassword(hexpass);
        adminDao.adminRegister(admin);
        admin_data = adminDao.getAdminByUsername(admin.getUsername());
        return admin_data;
    }
}
